package com.gitee.minimalismstyle.fresh.common.data.beetl.model

import org.beetl.sql.core.page.DefaultPageResult
import org.beetl.sql.core.page.PageRequest
import org.beetl.sql.core.page.PageResult

class FreshPageRequest<T>(var page: Long = 0,var size: Int = 20) : PageRequest<T> {

    var sort: String? = null
    var totalRequired: Boolean = false
    var listRequired: Boolean = false

    override fun getPageNumber(): Long {
        return page
    }

    override fun getPageSize(): Int {
        return size
    }

    override fun getOrderBy(): String? {
        return sort
    }

    override fun isTotalRequired(): Boolean {
        return totalRequired
    }

    override fun isListRequired(): Boolean {
        return listRequired
    }


    override fun of(result: List<T>): PageResult<*>? {
        val pageResult: DefaultPageResult<T> = DefaultPageResult<T>()
        pageResult.page = pageNumber
        pageResult.pageSize = pageSize
        pageResult.setList(result)
        return pageResult
    }

    override fun of(result: List<T>, total: Long): PageResult<*>? {
        val pageResult: DefaultPageResult<T> = DefaultPageResult<T>()
        pageResult.totalRow = total
        pageResult.setList(result)
        pageResult.page = this.pageNumber
        pageResult.pageSize = this.pageSize
        return pageResult
    }
}